<template>
  <div class="popup flex-center flex-align-items-center">
    <div class="main">
      <div class="main-header">
        <p>编辑推广计划名称</p>
        <i class="iconfont icon-guanbi" @click="close"></i>
      </div>
      <el-form ref="ruleFormRef" :model="form" :rules="rules" label-position="top" class="rule-form">
        <el-form-item label="视频链接" prop="url">
          <el-input v-model="form.url"></el-input>
        </el-form-item>
        <div class="btns flex">
          <p class="font-14 pointer" @click="submitForm(ruleFormRef)">确定</p>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import { defineEmits, ref } from 'vue';

const emit = defineEmits(['close', 'change']);

const rules = {
  url: [
    { required: true, message: '请输入视频链接', trigger: 'blur' },
  ]
};

const form = ref({});
const ruleFormRef = ref();

const close = () => {
  emit('close', null);
}
const submitForm = async formEl => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      emit('change', form.value.url);
    } else {
      console.log('error submit!', fields)
    }
  })
}
</script>

<style lang="less" scoped>
.popup {
  .main {
    position: relative;
    width: 390px;
    border-radius: 10px;
    background: #fff;

    .rule-form {
      padding: 16px 24px;

      &::v-deep {
        .el-form-item__content {
          margin-bottom: 18px;
        }

        input {
          height: 32px;
        }
      }

      .rule-form-top {
        &::v-deep {
          .el-select {
            width: 100%;
          }
        }
      }

      .rule-form-bottom {
        &::v-deep {
          .el-form-item {
            &:first-child {
              width: 140px;
            }

            &:last-child {
              width: 186px;
            }

            .el-form-item__content {
              margin-bottom: 0;
            }
          }
        }
      }

      .btns {
        margin-top: 25px;
        justify-content: end;

        p {
          transition: .1s;
          padding: 10px 20px;
          border-radius: 4px;
          color: #fff;
          background-color: #ff5277;
          border-color: #ff5277;
        }
      }
    }
  }
}
</style>
